package com.pms.controller;

import java.io.IOException;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.pms.service.PackagesService;
import com.pms.domain.Packages;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;


@Controller
@RequestMapping("/package")
public class PackagesController {

	@Autowired
	private PackagesService packagesService;
	
	@RequestMapping(value = "/query.pfv",method = { RequestMethod.POST, RequestMethod.GET })
	@ResponseBody
	public String getpackages() throws IOException {
		List<Packages> list = packagesService.getAll();
		return new String(JSONArray.fromObject(list).toString().getBytes(),"utf-8");
	}

	@RequestMapping(value = "/getByPackageId.pfv",method = { RequestMethod.POST, RequestMethod.GET })
	@ResponseBody
	public String getPackagesByPackageId(@RequestParam(value="packageId")String packageId ) throws IOException {
		Packages packages = packagesService.selectByPackageId(packageId) ;
		return new String(JSONObject.fromObject(packages).toString().getBytes(),"utf-8");
	}
	
	@RequestMapping(value = "/insert.pfv",method = { RequestMethod.POST, RequestMethod.GET })
	@ResponseBody
	public void insertPackages(@RequestParam(value="packages")Packages packages) {
		packagesService.insertPackages(packages);
	}
	
	@RequestMapping(value = "/update.pfv",method = { RequestMethod.POST, RequestMethod.GET })
	@ResponseBody
	public void updatePackages(@RequestParam(value="packages")Packages packages){
		packagesService.updateByPackageId(packages);
	}
	
	@RequestMapping(value = "/delete.pfv",method = { RequestMethod.POST, RequestMethod.GET })
	@ResponseBody
	public void deletePackages(@RequestParam(value="packageId")String packageId){
		packagesService.deleteByPackageId(packageId);
	}
}

